using MicroMsg.Common.Event;
using MicroMsg.Common.Utils;
using MicroMsg.Manager;
using MicroMsg.Protocol;
using MicroMsg.Resource.@string;
using MicroMsg.Scene;
using MicroMsg.Storage;
using MicroMsg.UI.UserContrl;
using MicroMsg.UI.Util;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
namespace MicroMsg.UI.Page
{
	public class PhoneNumBinding : BasePage
	{
		private const string TAG = "PhoneNumBinding";
		private const int ENABLE_BIND_VIEW = 1;
		private const int INPUT_PHONE_NUM_VIEW = 2;
		private const int VALID_CODE_VIEW = 3;
		private const int SHOW_NUM_NOTVERIFY_VIEW = 4;
		private const int BIND_SUCCESS_VIEW = 5;
		public const string bIsEnabledAddrBookMatchKey = "bIsEnabledAddrBookMatch";
		private bool mBIsLoaded;
		private NetSceneBindOpMobile mNetSceneBindOpMobile;
		private string cuPhoneNum;
		private EventWatcher mBindValidWatcher;
		private EventWatcher mBindFailWatcher;
		private EventWatcher mBindSuccessWatcher;
		internal Grid LayoutRoot;
		internal Grid sencondRoot;
		internal Grid ContentPanel;
		internal ViewFlipper BindViewFlipper;
		internal StackPanel StartBindView;
		internal Button StartBindBtn;
		internal StackPanel EnableBindView;
		internal Image imgPhone1;
		internal Button EnableBindBtn;
		internal StackPanel InputPhoneNumView;
		internal InputPhoneNumCtrl mPhoneNumInputer;
		internal Button InputOKBtn;
		internal StackPanel ValidCodeView;
		internal TextBlock PhoneNumInfo;
		internal PhoneTextBox InputValidCodeTxt;
		internal Button ValidCodeBtn;
		internal Button btnGetVoiceCode;
		internal StackPanel panelNotVerified;
		internal Image imgPhoneNotVerified;
		internal TextBlock txtNumNotVerify;
		internal Button btnNotVerifyToVerify;
		internal Button btnRemoveNotVerified;
		internal StackPanel BindSuccessView;
		internal Image imgPhone;
		internal TextBlock BindingSuccessPhoneNum;
		internal Button BindingSuccessBtn;
		private bool _contentLoaded;
		protected override void OnPageIn(object[] object_0)
		{
			Log.smethod_5("PhoneNumBinding", "OnPageIn");
			if (!this.mBIsLoaded)
			{
				this.mBIsLoaded = true;
				Account curAccount = AccountMgr.getCurAccount();
				if (ToolFunction.checkIsPhoneNumber(curAccount.strBindMobile) && !AccountMgr.MobileVerify)
				{
					this.txtNumNotVerify.set_Text(curAccount.strBindMobile);
					this.mPhoneNumInputer.txtInNumber.set_Text(curAccount.strBindMobile);
					this.cuPhoneNum = curAccount.strBindMobile;
					this.showView(4);
					return;
				}
				this.showView(1);
			}
		}
		protected override void OnPageOut()
		{
			Log.smethod_5("PhoneNumBinding", "OnPageOut");
		}
		public PhoneNumBinding()
		{
			this.InitializeComponent();
			base.add_Loaded(new RoutedEventHandler(this.PhoneNumBinding_Loaded));
			base.add_Unloaded(new RoutedEventHandler(this.PhoneNumBinding_Unloaded));
			this.setAppBar();
		}
		private void PhoneNumBinding_Unloaded(object sender, RoutedEventArgs e)
		{
			Log.smethod_5("PhoneNumBinding", "OnPageOut");
			this.UnitBinding();
		}
		private void PhoneNumBinding_Loaded(object sender, RoutedEventArgs e)
		{
			Log.smethod_5("PhoneNumBinding", "OnPageIn");
			this.InitBinding();
		}
		private void InitBinding()
		{
			this.mNetSceneBindOpMobile = new NetSceneBindOpMobile();
			this.mBindValidWatcher = new EventWatcher(this, this, new EventHandlerDelegate(this.onBindValidEventHandler));
			EventCenter.registerEventWatcher(EventConst.ON_NETSCENE_BINDMOBILE_NEEDVERIFY, this.mBindValidWatcher);
			this.mBindFailWatcher = new EventWatcher(this, this, new EventHandlerDelegate(this.onBindFailEventHandler));
			EventCenter.registerEventWatcher(EventConst.ON_NETSCENE_BINDMOBILE_ERR, this.mBindFailWatcher);
			this.mBindSuccessWatcher = new EventWatcher(this, this, new EventHandlerDelegate(this.onBindSuccessEventHandler));
			EventCenter.registerEventWatcher(EventConst.ON_NETSCENE_BINDMOBILE_SUCCESS, this.mBindSuccessWatcher);
		}
		private void UnitBinding()
		{
			EventCenter.removeEventWatcher(EventConst.ON_NETSCENE_BINDMOBILE_NEEDVERIFY, this.mBindValidWatcher);
			EventCenter.removeEventWatcher(EventConst.ON_NETSCENE_BINDMOBILE_ERR, this.mBindFailWatcher);
			EventCenter.removeEventWatcher(EventConst.ON_NETSCENE_BINDMOBILE_SUCCESS, this.mBindSuccessWatcher);
		}
		private void onBindValidEventHandler(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			this.PhoneNumInfo.set_Text(strings.PCon_Bind_TxtMLead2 + this.cuPhoneNum);
			ProcessingCover.releaseProgressBar(this.LayoutRoot);
			this.InputValidCodeTxt.set_Text("");
			this.showView(3);
		}
		private void onBindFailEventHandler(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			ProcessingCover.releaseProgressBar(this.LayoutRoot);
			RetConst retConst = (RetConst)evtArgs.mObject;
			RetConst retConst2 = retConst;
			if (retConst2 <= RetConst.MM_ERR_MOBILE_NEEDADJUST)
			{
				if (retConst2 == RetConst.MM_ERR_CLIENT)
				{
					MMMessageBox.Show("", strings.Reg_PhoneNum_MsgBadNet, 1, true, strings.COM_Confirm, "取消");
					return;
				}
				if (retConst2 == RetConst.MM_ERR_MOBILE_NEEDADJUST)
				{
					MMMessageBox.Show(strings.PCon_Bind_Msg_BindPhone_NeedAdjust, true, "确定");
					return;
				}
			}
			else
			{
				if (retConst2 == RetConst.MM_ERR_MOBILE_FORMAT)
				{
					MMMessageBox.Show(strings.PCon_Bind_Msg_BindPhone_FormatTip, true, "确定");
					return;
				}
				if (retConst2 == RetConst.MM_ERR_FREQ_LIMITED)
				{
					MMMessageBox.Show(strings.Reg_PhoneNum_MsgTooFreq, true, "确定");
					return;
				}
			}
			if (this.BindViewFlipper.GetCuViewIndex() == 2)
			{
				RetConst retConst3 = retConst;
				switch (retConst3)
				{
				case RetConst.MM_ERR_USER_BIND_MOBILE:
					break;
				case RetConst.MM_ERR_USER_MOBILE_UNMATCH:
					goto IL_A8;
				case RetConst.MM_ERR_MOBILE_FORMAT:
					MMMessageBox.Show(strings.Reg_PhoneNum_MsgBadNum, true, "确定");
					return;
				default:
					if (retConst3 != RetConst.MM_ERR_MOBILE_BINDED)
					{
						goto IL_A8;
					}
					break;
				}
				MMMessageBox.Show(strings.PCon_Bind_MsgDupNum, true, "确定");
				return;
				IL_A8:
				MMMessageBox.Show(strings.Reg_PhoneNum_MsgBadNum, true, "确定");
				return;
			}
			if (this.BindViewFlipper.GetCuViewIndex() == 3)
			{
				MMMessageBox.Show(strings.PCon_Bind_MsgBadV, true, "确定");
				return;
			}
			if (this.BindViewFlipper.GetCuViewIndex() == 4)
			{
				MMMessageBox.Show(strings.PCon_Bind_MsgDupNum, true, "确定");
			}
		}
		private void onBindSuccessEventHandler(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			this.BindingSuccessPhoneNum.set_Text(this.cuPhoneNum);
			ProcessingCover.releaseProgressBar(this.LayoutRoot);
			this.showView(5);
		}
		private void StartBindBtn_Click(object sender, RoutedEventArgs e)
		{
			this.showView(1);
		}
		private void EnableBindBtn_Click(object sender, RoutedEventArgs e)
		{
			if (ConfigMgr.getBool("bIsEnabledAddrBookMatch", false) && ToolFunction.checkIsPhoneNumber(AccountMgr.strBindMobile) && AccountMgr.MobileVerify)
			{
				base.GoToPage("/Source/UI/PhoneContact/ViewPhoneContact.xaml", null, true);
				return;
			}
			MMMessageBox mMMessageBox = MMMessageBox.Show(strings.Login_Main_MsgAskMobileTitle, strings.PCon_Bind_MsgAskMobileCon, true, strings.COM_Confirm, strings.COM_Cancel);
			mMMessageBox.ReturnEvent = new DlgReturnEvent(this.AlertReturn);
		}
		public void AlertReturn(DlgReturnEventArg dlgReturnEventArg_0)
		{
			switch (MMMessageBox.GetUserClickResult(dlgReturnEventArg_0))
			{
			case 0:
				ConfigMgr.setBool("bIsEnabledAddrBookMatch", true);
				if (ToolFunction.checkIsPhoneNumber(AccountMgr.strBindMobile) && AccountMgr.MobileVerify)
				{
					base.GoToPage("/Source/UI/PhoneContact/ViewPhoneContact.xaml", null, true);
					return;
				}
				this.showView(2);
				break;
			case 1:
				break;
			default:
				return;
			}
		}
		private void InputOKBtn_Click(object sender, RoutedEventArgs e)
		{
			this.cuPhoneNum = this.mPhoneNumInputer.GetPhoneNumber();
			if (!ToolFunction.checkIsPhoneNumber(this.cuPhoneNum))
			{
				MessageBoxManager.ShowToast(strings.PCon_Bind_MsgBadNum, 2500, null, false);
				return;
			}
			this.mNetSceneBindOpMobile.doSceneBindMobile(this.cuPhoneNum);
			ProcessingCover.getProgressBar(this.LayoutRoot, strings.PCon_Bind_MsgSending, null, false, false, null);
		}
		public void inputDone(object sender, object object_0)
		{
		}
		public void inputNotDone(object sender, object object_0)
		{
		}
		private void btnNotVerifyToVerify_Click(object sender, RoutedEventArgs e)
		{
			this.mNetSceneBindOpMobile.doSceneBindMobile(this.txtNumNotVerify.get_Text());
			ProcessingCover.getProgressBar(this.LayoutRoot, strings.PCon_Bind_MsgSending, null, false, false, null);
		}
		private void btnRemoveNotVerified_Click(object sender, RoutedEventArgs e)
		{
			AccountMgr.strBindMobile = "";
			AccountMgr.updateAccount();
			this.showView(1);
			this.mPhoneNumInputer.ResetInput();
			this.InputValidCodeTxt.set_Text("");
			ServiceCenter.sceneBindMobile.doSceneUnBindMobile(AccountMgr.strBindMobile);
		}
		private void ValidCodeBtn_Click(object sender, RoutedEventArgs e)
		{
			if (string.IsNullOrEmpty(this.InputValidCodeTxt.get_Text()))
			{
				MessageBoxManager.ShowToast(strings.PCon_Bind_MsgNoVCode, 2500, null, false);
				return;
			}
			this.mNetSceneBindOpMobile.doSceneVerifyForBindMobile(this.InputValidCodeTxt.get_Text());
			ProcessingCover.getProgressBar(this.LayoutRoot, strings.PCon_Bind_MsgBinding, null, false, false, null);
		}
		private void btnGetVerifyCodeByVoice_Click(object sender, RoutedEventArgs e)
		{
			base.GoToPage("/Source/UI/LoginViews/RegByPhoneStepVoiceCode.xaml", new object[]
			{
				"bind"
			}, false);
		}
		private void BindingSuccessBtn_Click(object sender, RoutedEventArgs e)
		{
			base.GoToPage("/Source/UI/PhoneContact/ViewPhoneContact.xaml", null, true);
		}
		protected override void OnBackKeyPress(CancelEventArgs cancelEventArgs_0)
		{
			int cuViewIndex = this.BindViewFlipper.GetCuViewIndex();
			if (3 == cuViewIndex)
			{
				this.showView(2);
				cancelEventArgs_0.set_Cancel(true);
			}
		}
		public void setAppBar()
		{
			if (base.get_ApplicationBar() != null && 1 == base.get_ApplicationBar().get_Buttons().get_Count())
			{
				ApplicationBarIconButton applicationBarIconButton = (ApplicationBarIconButton)base.get_ApplicationBar().get_Buttons().get_Item(0);
				applicationBarIconButton.set_Text(strings.COM_Next);
				this.setAppBarStyle(base.get_ApplicationBar());
			}
		}
		private void btnNextStep_Click(object sender, EventArgs e)
		{
			this.cuPhoneNum = this.mPhoneNumInputer.GetPhoneNumber();
			if (!ToolFunction.checkIsPhoneNumber(this.cuPhoneNum))
			{
				MessageBoxManager.ShowToast(strings.PCon_Bind_MsgBadNum, 2500, null, false);
				return;
			}
			base.Focus();
			this.mNetSceneBindOpMobile.doSceneBindMobile(this.cuPhoneNum);
			ProcessingCover.getProgressBar(this.LayoutRoot, strings.PCon_Bind_MsgSending, null, false, false, null);
		}
		private void showView(int nViewIndex)
		{
			if (nViewIndex == 2)
			{
				if (base.get_ApplicationBar() != null)
				{
					base.get_ApplicationBar().set_IsVisible(true);
				}
			}
			else
			{
				if (base.get_ApplicationBar() != null)
				{
					base.get_ApplicationBar().set_IsVisible(false);
				}
			}
			this.BindViewFlipper.ShowView(nViewIndex);
			if (this.isChinaPhone())
			{
				this.btnGetVoiceCode.set_Visibility(1);
				return;
			}
			this.btnGetVoiceCode.set_Visibility(0);
		}
		private bool isChinaPhone()
		{
			return !string.IsNullOrEmpty(this.cuPhoneNum) && string.Compare("+86", 0, this.cuPhoneNum, 0, 3) == 0;
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/UI/PhoneContact/PhoneNumBinding.xaml", 2));
			this.LayoutRoot = (Grid)base.FindName("LayoutRoot");
			this.sencondRoot = (Grid)base.FindName("sencondRoot");
			this.ContentPanel = (Grid)base.FindName("ContentPanel");
			this.BindViewFlipper = (ViewFlipper)base.FindName("BindViewFlipper");
			this.StartBindView = (StackPanel)base.FindName("StartBindView");
			this.StartBindBtn = (Button)base.FindName("StartBindBtn");
			this.EnableBindView = (StackPanel)base.FindName("EnableBindView");
			this.imgPhone1 = (Image)base.FindName("imgPhone1");
			this.EnableBindBtn = (Button)base.FindName("EnableBindBtn");
			this.InputPhoneNumView = (StackPanel)base.FindName("InputPhoneNumView");
			this.mPhoneNumInputer = (InputPhoneNumCtrl)base.FindName("mPhoneNumInputer");
			this.InputOKBtn = (Button)base.FindName("InputOKBtn");
			this.ValidCodeView = (StackPanel)base.FindName("ValidCodeView");
			this.PhoneNumInfo = (TextBlock)base.FindName("PhoneNumInfo");
			this.InputValidCodeTxt = (PhoneTextBox)base.FindName("InputValidCodeTxt");
			this.ValidCodeBtn = (Button)base.FindName("ValidCodeBtn");
			this.btnGetVoiceCode = (Button)base.FindName("btnGetVoiceCode");
			this.panelNotVerified = (StackPanel)base.FindName("panelNotVerified");
			this.imgPhoneNotVerified = (Image)base.FindName("imgPhoneNotVerified");
			this.txtNumNotVerify = (TextBlock)base.FindName("txtNumNotVerify");
			this.btnNotVerifyToVerify = (Button)base.FindName("btnNotVerifyToVerify");
			this.btnRemoveNotVerified = (Button)base.FindName("btnRemoveNotVerified");
			this.BindSuccessView = (StackPanel)base.FindName("BindSuccessView");
			this.imgPhone = (Image)base.FindName("imgPhone");
			this.BindingSuccessPhoneNum = (TextBlock)base.FindName("BindingSuccessPhoneNum");
			this.BindingSuccessBtn = (Button)base.FindName("BindingSuccessBtn");
		}
	}
}
